package com.jingyanzi.resallocation.client;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jingyanzi.resallocation.domain.SiteDO;
import com.jingyanzi.resallocation.query.SiteQueryDO;
import com.jingyanzi.resallocation.result.ResultDO;
import com.jingyanzi.resallocation.result.ResultSupport;
import com.jingyanzi.resallocation.service.ISiteService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(description = "场景接口")
@RestController
@RequestMapping("/api")
public class SiteClientImpl {

	@Autowired
	private ISiteService siteService;
	
	@ApiOperation(value = "获取场景" ,  notes="获取场景")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "场景Id", required = true, dataType = "Integer"),
    })
	@RequestMapping("/site/{id}")
	public SiteDO get(@PathVariable(value = "id") Integer id) {
		ResultDO result = siteService.get(id);
		SiteDO siteDO = (SiteDO) result.getModel(ResultSupport.FIRST_MODEL_KEY);
		return siteDO;
	}
	
	@RequestMapping("/site/{type}/{region}")
	public List<SiteDO> query(@PathVariable(value = "type") Integer type,
			@PathVariable(value = "region") String region) {
		SiteQueryDO query = new SiteQueryDO();
		query.setSceneType(type);
		if(region.equals("all")) {
			query.setRegion(null);
		} else {
			region = region.replace("_", "/");
			query.setRegion(region);
		}
		ResultDO result = siteService.query(query);
		List<SiteDO> list = (List<SiteDO>) result.getModel(ResultSupport.FIRST_MODEL_KEY);
		return list;
	}
}
